package com;

import cn.hutool.core.lang.Singleton;
import cn.hutool.core.util.StrUtil;
import com.modular.event.opt.OptAlarmEvent;
import com.modular.event.opt.OptAlarmRecords;
import com.c.opt.ComOpt;
import com.modular.iot.bean.ThingsDeviceCmdDo;
import com.modular.iot.opt.*;
import com.modular.logs.OptLog;
import com.modular.scene.OptScene;
import com.modular.scene.opt.OptSceneWeather;
import com.modular.system.dict.OptDict;
import com.modular.system.msg.opt.OptMsg;
import com.modular.system.task.opt.OptSysTaskCom;
import ntd.util.modular.data.entity.DataAcquisitionRecords;
import ntd.util.modular.things.entity.DeviceData;
import ntd.util.modular.things.entity.DeviceDataItem;
import ntd.util.modular.things.entity.Service;

/**
 * opt 操作工具
 */
public class ToolOpt {

    /** 设备操作对象 */
    public static final OptIotDevice OPT_T_DEVICE = Singleton.get(OptIotDevice.class);
    /** 设备数据操作对象 */
    public static final ComOpt<DeviceData> OPT_T_D_DATA = get("things_device_data", DeviceData.class);
    /** 设备数据操作对象 */
    public static final ComOpt<DeviceDataItem> OPT_T_D_D_ITEM = get("things_device_data_item", DeviceDataItem.class);
    /** 设备指令操作对象 */
    public static final ComOpt<ThingsDeviceCmdDo> OPT_T_D_CMD = get("things_device_cmd", ThingsDeviceCmdDo.class);
    /** 设备配置操作对象 */
    public static final OptIotDeviceConfig OPT_T_D_CONFIG = Singleton.get(OptIotDeviceConfig.class);
    /** 设备数据 domain 操作对象 */
    public static final OptIotData OPT_T_DATA = Singleton.get(OptIotData.class);
    /** 产品操作对象 */
    public static final OptIotProduct OPT_T_PRODUCT = Singleton.get(OptIotProduct.class);
    /** 属性操作对象 */
    public static final OptIotAttribute OPT_T_ATTRIBUTE = Singleton.get(OptIotAttribute.class);
    /** 产品服务操作对象 */
    public static final ComOpt<Service> OPT_T_SERVICE = get("things_service", Service.class);

    /** IOT - 场景天气 */
    public static final OptSceneWeather OPT_T_SCENE_WEATHER = Singleton.get(OptSceneWeather.class);

    /** 场景操作对象 */
    public static final OptScene OPT_SCENE_BASE = Singleton.get(OptScene.class);

    /** 数据因子编码操作对象 */
    public static final OptDataFactorCom OPT_D_FACTOR = Singleton.get(OptDataFactorCom.class);

    /** 系统任务操作对象 */
    public static final OptSysTaskCom OPT_S_TASK = Singleton.get(OptSysTaskCom.class);
    /** 系统任务操作对象 */
    public static final OptDict OPT_S_DICT = Singleton.get(OptDict.class);

    /** 系统消息操作对象 */
    public static final OptMsg OPT_MSG = Singleton.get(OptMsg.class);

    /** 系统日志操作对象 */
    public static final OptLog OPT_LOG = Singleton.get(OptLog.class);

    /** 告警事件操作对象 */
    public static final OptAlarmEvent OPT_ALARM_EVENT = Singleton.get(OptAlarmEvent.class);
    public static final OptAlarmRecords OPT_ALARM_RECORDS = Singleton.get(OptAlarmRecords.class);

    /** 数据采集记录操作对象 */
    public static final ComOpt<DataAcquisitionRecords> OPT_D_A_RECORDS = get("data_acquisition_records", DataAcquisitionRecords.class);

    public static <T> ComOpt<T> get(String tName) {
        return Singleton.get(tName, () -> new ComOpt<T>(tName){});
    }

    public static <T> ComOpt<T> get(String tName, Class<T> clazz) {
        return Singleton.get(tName, () -> new ComOpt<T>(tName){}.bean(clazz));
    }

    public static <T> ComOpt<T> get(String tName, String dsId) {
        return Singleton.get(StrUtil.format("{}-{}", dsId, tName), () -> new ComOpt<T>(tName, dsId){});
    }

    public static <T> ComOpt<T> get(String tName, String dsId, Class<T> clazz) {
        return Singleton.get(StrUtil.format("{}-{}", dsId, tName), () -> new ComOpt<T>(tName, dsId){}.bean(clazz));
    }

}
